<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品信息编辑</title>
<#include "/WEB-INF/content/module-edit.html">
<link href="${request.contextPath}/res/kindeditor/themes/default/default.css" rel="stylesheet" />
<script charset="utf-8" src="${request.contextPath}/res/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="${request.contextPath}/res/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript">
var sysStatus = [
    {"id":"0","text":"正常"},
    {"id":"1","text":"禁用"}
];
var oper=[
	{"id":"0","text":"上架"},
	{"id":"1","text":"下架"}
];
var pos=[
	{"id":"0","text":"是"},
   	{"id":"1","text":"否"}
];
var typeTree=[
<#list map.typeTree as item>
   	<#if item_has_next>
   		{"id":"${item.id}","text":"${item.text}",
"children":[
<#list item.children as ite>
	<#if ite_has_next>
 		{"id":"${ite.id}","text":"${ite.text}"},  			
	<#else>
		{"id":"${ite.id}","text":"${ite.text}"}
	</#if>
</#list>
]},
   	<#else>
   		{"id":"${item.id}","text":"${item.text}",
   		"children":[
   		<#list item.children as ite>
   			<#if ite_has_next>
   		 		{"id":"${ite.id}","text":"${ite.text}"},  			
   			<#else>
   				{"id":"${ite.id}","text":"${ite.text}"}
   			</#if>
   		</#list>
   		]}
   	</#if>
</#list>
];
KindEditor.ready(function(K) {
    window.editor = K.create('#productdesc', {
        langType : 'zh_CN',
        height:"400px",
        uploadJson : '${request.contextPath}/res/kindeditor/jsp/upload_json_textarea.jsp',
        fileManagerJson : '${request.contextPath}/res/kindeditor/jsp/file_manager_json.jsp',
        allowFileManager :false,
        items:['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
               'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
               'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
               'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
               'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
               'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'table', 'hr', 'baidumap', 'pagebreak',
               'anchor', 'link', 'unlink', '|', 'about'
       ],themeType : 'simple',
       });
});
$(function() {
  	$("#status").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
  		data:sysStatus
  	}); 
  	$("#isshowplaceinfo").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
  		data:pos
  	});   	
  	$("#productstatus").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
  		data:oper
  	});
  	$("#isrecommend").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
  		data:pos
  	});
  /* 	$("#parent").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
        required:true,
  		data:typeTree,
  		onChange:function(data){
  			for(var i in typeTree){
  				if(typeTree[i].id==data){
  					$("#ptid").combobox({
  				  		valueField : 'id',
  				  		textField : 'text',
  				  		editable:false,
  				        panelHeight:'auto',
  				        required:true,
  				        value:"",
  				  		data:typeTree[i].children
  					});
  				}
  			}
  		}
  	});	   */
    <#if object.pid?exists&&object.pid!="">
/*     var sub;
    var parent=$("#parent").val();
    for(var i in typeTree){
    	if(typeTree[i].id==parent){
    		sub=typeTree[i].children;
    	}
    } */
	$("#ptid").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
        required:true,
        data:typeTree
	});    
	<#else>
	$("#ptid").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
        required:true,
        data:typeTree
	});     
	$('#pid').validatebox({
		required : true,
		validType : [
				"code",
				'remote["${request.contextPath}/product/info/validate", "pid", "${object.pid!}"]' ]
	});
	</#if>  
   	$("#isrecommend").combobox({
		valueField : 'id',
		textField : 'text',
		editable:false,
		data:pos,
		onChange:function(data){
			if(data!=0){
				$("#recommenddate").datebox({ disabled: true}); 
				$("#recommenddate").datebox("setValue","");
			}else{
				$("#recommenddate").datebox({ disabled:false}); 
			}
		}
	}); 
	$('#attention').numberspinner({editable:true,min:0,increment:1 });	
  	$('#productamount').numberspinner({editable:true,min:1,increment:1 });
  	$('#salesamount').numberspinner({editable:true,min:0,increment:1 });
  	$("#shippingfee").numberbox({min:0,precision:2});
 });
 function mySave(){
	 var head="<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><title></title><meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no\" /><script type=\"text/javascript\">"+
	 "document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + 'px';"+
	 "<\/script><style type=\"text/css\">*{margin: 0;padding: 0;}img{width: 100%;padding-bottom: 0.4rem;}"+
	 "html{font-size: 0.24rem;font-family: sans-serif;line-height: 1.7rem;color: #787878;}@media screen and (max-width: 321px) {body {font-size:0.24rem;padding: 0.2rem;text-align: justify;}}@media screen and (min-width: 321px) and (max-width:400px) {body {font-size:0.28rem;padding: 0.2rem;text-align: justify;}}@media screen and (min-width: 400px) {body {font-size:0.30rem;padding: 0.2rem;text-align: justify;}}</style></head><body>";
	 var tail="</body></html>";
	 var value=$("#productdesc").val();
	 if(value.indexOf("<!DOCTYPE")==-1){
		 $("#productdesc").val(head+value+tail);
	 }
	 save();
 }
</script>
<style>
.input-width{
	width: 95%;
}
</style>
 
</head>
<body class="easyui-layout">
	<div region="north" id="toolbar" style="background-color: #eee; padding: 5px; overflow: hidden;" border="false">
		<#if object.pid?exists&&object.pid!="">
			<@auth code="product:info:update">
				<a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-add" style="border: 1px solid #ccc" onclick="javascript:mySave()">保存</a>
			</@auth>
		<#else>
			<@auth code="product:info:create">
				<a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-add" style="border: 1px solid #ccc" onclick="javascript:mySave()">保存</a>
			</@auth>
		</#if>
		<a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-edit" style="border: 1px solid #ccc" onclick="javascript:cancel()">关闭</a>
	</div>
	<div region="center">
		<div id="p" class="easyui-panel" style="background: #fafafa; padding: 10px" fit="true" toolbar="#toolbar">
			<form id="form" method="post">
				<input type="hidden" id="_id" value="${(object.pid)!}"/>
				<table class="form" cellspacing="0" style="width: 100%">
					<tbody style="border: 1px solid #ccc">
						<tr>
							<td class="label">商品编号：</td>
							<td><input id="pid" name="pid" value="${(object.pid)!}" placeholder="数字加字母的组合" <#if object.pid?exists&&object.pid!="">readonly="readonly"</#if>></td>
							<td class="validate"></td>
							<td class="label">商品类型：</td>
							<td><!-- <input id="parent" value="${(map.typeparent)!}"> -->
								<input id="ptid" name="ptid" value="${(object.ptid)!}"/>
							</td>
							<td class="validate"></td>							
						</tr>
						<tr>
							<td class="label">商品名称:</td>
							<td><input id="productname" name="productname" value="${(object.productname)!}" style="width:90%;" class="easyui-validatebox" required="true"/></td>
							<td class="validate">*</td>
							<td class="label">已售数量:</td>
							<td><input id="salesamount" name="salesamount" value="${(object.salesamount)!0}" style="width:90%;" class="easyui-validatebox" required="true"/></td>
							<td class="validate">*</td>							
						</tr>
						<tr>
							<td class="label">副标题:</td>
							<td><input style="width:90%;" id="productintro" name="productintro" value="${object.productintro!}"/></td>
							<td class="validate"></td>
							<td class="label">配送费用:</td>
							<td><input id="shippingfee" name="shippingfee" value="${object.shippingfee!}" required="true"/></td>
							<td class="validate">*</td>
						</tr>						
						<tr>
							<td class="label">商品数量：</td>
							<td>
								<input id="productamount" name="productamount" required="true" value="${(object.productamount)!0}"/>
							</td>
							<td class="validate">*</td>
							<td class="label">单位:</td>
							<td><input id="quantifier" name="quantifier" required="true" value="${object.quantifier!}"/></td>
							<td class="validate">*</td>							
 						<tr>
							<td class="label">是否推荐：</td>
							<td><input id="isrecommend" name="isrecommend" value="${object.isrecommend!'0'}" /></td>
							<td class="validate"></td>		
							<td class="label">推荐日期：</td>
							<td><input id="recommenddate" name="recommenddate" class="easyui-datebox" value="${(object.recommenddate)!}" editable="false"/></td>
							<td class="validate"></td>												
						</tr>
						<tr>
							<td class="label">分享标题：</td>
							<td><input style="width:90%;" id="sharetitle" name="sharetitle" value="${(object.sharetitle)!}"/></td>
							<td class="validate"></td>						
							<td class="label">关注度：</td>
							<td><input id="attention" name="attention" required="true" value="${(object.attention)!0}"/>
							<td class="validate"></td>
						</tr>		
						<tr>
							<td class="label">显示销售点：</td>
							<td><input id="isshowplaceinfo" name="isshowplaceinfo" required="true" value="${object.isshowplaceinfo!'0'}" /></td>
							<td class="validate"></td>							
							<td class="label">状态：</td>
							<td><input id="status" name="status" required="true" value="${object.status!'0'}" /></td>
							<td class="validate"></td>							
						</tr>			
						<tr>
							<td class="label">分享描述：</td>
							<td colspan="4"><textarea style="width:90%;" id="sharedesc" name="sharedesc" required="true">${(object.sharedesc)!}</textarea>
							<td class="validate"></td>
						</tr>
						<tr>
							<td class="label">商品详情:</td>
							<td colspan="4"><textarea style="width:90%;" id="productdesc" name="productdesc">${object.productdesc!}</textarea></td>
							<td class="validate"></td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>
	</div>
</body>
</html>